package xyz.chaobei.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import xyz.chaobei.enums.IntegerEnum;

import java.util.Date;

@Slf4j
@Component
@ConfigurationProperties(prefix = "meta.fill")
@Data
public class MyMetaObjectHandler implements MetaObjectHandler {

    private String installTime;
    private String installStatus;
    private String updateTime;

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.strictInsertFill(metaObject, installTime, Date.class, new Date()); // 起始版本 3.3.0(推荐使用)
        this.strictInsertFill(metaObject, installStatus, Integer.class, IntegerEnum.LOCK.getVal());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.strictUpdateFill(metaObject, updateTime, Date.class, new Date()); // 起始版本 3.3.0(推荐使用)
    }
}